package com.pig4cloud.pigx.contract.feign;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.pig4cloud.pigx.contract.entity.ContractTrade;
import com.pig4cloud.pigx.contract.service.ContractTradeService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 抓取行情记录表Feign 实现层
 *
 * @date 2022-08-20 15:42:00
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/contract-market-record" )
@Api(value = "contract-market-record", tags = "")
public class ContractMarketRecordController {

	private final ContractTradeService contractTradeService;

	/**
	 * 获取昨日8点到今日8点之前的交易记录
	 * @return List<ContractTrade>
	 */
	@GetMapping("/time/contract")
	public List<ContractTrade> getSettlementOrder() {
		// 定时任务每天8点执行，获取昨日8点到今日8点前的交易记录
		LocalDateTime endTime = LocalDateTime.now();
		LocalDateTime startTime = endTime.minusDays(-1);
		BaseMapper<ContractTrade> mapper = contractTradeService.getBaseMapper();
		return mapper.selectList(new QueryWrapper<ContractTrade>() {{
			ge("create_time", startTime);
			lt("create_time", endTime);
			// 查询未删除
			eq("is_deleted","0");
		}});
	}
}
